using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ProductManage : Member, IRequiresSessionState
{
	private string linkHead = "";
	private int _selectone = -1;
	protected Literal ltrPageTitle;
	protected TextBox ProductList;
	protected HiddenField hfProductList;
	protected DropDownList ddlProdcutType;
	protected Literal ltrProductType;
	protected TextBox txtProductName;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected HtmlForm productform;
	public int selectone
	{
		get
		{
			if (base.Request.QueryString["SelectOne"] != null)
			{
				this._selectone = Convert.ToInt32(base.Request.QueryString["SelectOne"].ToString());
			}
			return this._selectone;
		}
		set
		{
			this._selectone = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.hfProductList.Value = Fetch.Get("DefaultValue");
			if (!string.IsNullOrEmpty(this.hfProductList.Value))
			{
				string sql = "select ProductID,ProductName from HLShop_Product where ProductID in (" + this.hfProductList.Value + ")";
				DataTable dataTable = this.conn.GetDataTable(sql);
				string text = "";
				string text2 = "";
				string[] array = this.hfProductList.Value.Split(new char[]
				{
					','
				});
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					text = text + dataTable.Rows[i]["ProductName"].ToString() + ",";
					text2 = text2 + dataTable.Rows[i]["ProductID"].ToString() + ",";
				}
				if (text != "")
				{
					text = text.Substring(0, text.Length - 1);
					text2 = text2.Substring(0, text2.Length - 1);
				}
				this.ProductList.Text = text;
				this.hfProductList.Value = text2;
			}
			this.BindProduct();
		}
	}
	protected void BindProduct()
	{
		string query = this.GetQuery();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		ClientByPage clientByPage = new ClientByPage();
		string text = " from HLShop_Product where SalerID=" + base.user.UserID;
		int pageSize = this.gvManage.PageSize;
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "(select ShopName from HLShop_Shop where ShopID=HLShop_Product.ShopID) ShopName,";
		string str2 = "(select UserName from HL_User where UserID=HLShop_Product.SalerID) as SalerName,";
		string str3 = " ROW_NUMBER() OVER (order by ProductID desc) as row," + str + str2 + "*";
		string strSQL = "select " + str3 + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		if (this.selectone == 1)
		{
			if (this.gvManage.Rows.Count > 0)
			{
				HtmlInputCheckBox htmlInputCheckBox = this.gvManage.HeaderRow.Cells[0].FindControl("chkAll") as HtmlInputCheckBox;
				if (htmlInputCheckBox != null)
				{
					htmlInputCheckBox.Disabled = true;
				}
			}
		}
		CurrPageLinks currPageLinks = new CurrPageLinks();
		if (this.selectone == 1)
		{
			this.linkHead = this.linkHead + "&SelectOne=" + this.selectone;
		}
		string url = "?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductTypeSel");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlProdcutType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlProdcutType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2) && text2 != "0")
		{
			text = text + " and ProductType=" + text2;
		}
		this.linkHead = this.linkHead + "&ProductTypeSel=" + text2;
		if (base.Request.QueryString["ProductType"] != null)
		{
			string text3 = base.Request.QueryString["ProductType"].ToString();
			if (text3 == "4")
			{
				this.ddlProdcutType.Style["display"] = "none";
				this.ltrProductType.Text = "促销(秒杀)商品";
				text = text + " and ProductType=" + text3;
			}
		}
		string text4 = Fetch.Get("ProductName");
		if (!string.IsNullOrEmpty(text4))
		{
			if (text4 != this.txtProductName.Text.Trim())
			{
				text4 = this.txtProductName.Text.Trim();
			}
			this.txtProductName.Text = text4;
		}
		else
		{
			text4 = this.txtProductName.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and ProductName like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&ProductName=" + text4;
		}
		return text;
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindProduct();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindProduct();
	}
}
